package com.longrise.android.byjk.plugins.tabfirst.revision;

import android.media.MediaPlayer;
import android.text.TextUtils;

import com.longrise.android.byjk.utils.Tracker_Google;

/**
 * Created by godliness on 2017/3/22.
 * tracker video play error status
 */
public class MediaErrorTracker {

    private static void switchTracker(int status, int what, int extra) {
        String whatStr = "";
        String extraStr = "";
        switch (what) {
            case MediaPlayer.MEDIA_ERROR_IO:
                whatStr = "what" + what + " : MEDIA_ERROR_IO --> File or network related operation errors";
                break;
            case MediaPlayer.MEDIA_ERROR_MALFORMED:
                whatStr = "what" + what + " : MEDIA_ERROR_MALFORMED --> Bitstream is not conforming to the related coding standard or file spec";
                break;
            case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
                whatStr = "what" + what + " : MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK --> The video is streamed and its container is not valid for progressive playback i.e the video's index (e.g moov atom) is not at the start of the file";
                break;
            case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                whatStr = "what" + what + " : MEDIA_ERROR_SERVER_DIED --> Media server died. In this case, the application must release the MediaPlayer object and instantiate a new one";
                break;
            case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
                whatStr = "what" + what + " : MEDIA_ERROR_TIMED_OUT --> Some operation takes too long to complete, usually more than 3-5 seconds";
                break;
            case MediaPlayer.MEDIA_ERROR_UNKNOWN:
                whatStr = "what" + what + " : MEDIA_ERROR_UNKNOWN --> Unspecified media player error";
                break;
            case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
                whatStr = "what" + what + " : MEDIA_ERROR_UNSUPPORTED --> the media framework does not support the feature";
                break;
        }
        switch (extra) {
            case MediaPlayer.MEDIA_ERROR_IO:
                extraStr = "extra" + extra + " : MEDIA_ERROR_IO --> : File or network related operation errors";
                break;
            case MediaPlayer.MEDIA_ERROR_MALFORMED:
                extraStr = "extra" + extra + " : MEDIA_ERROR_MALFORMED --> : Bitstream is not conforming to the related coding standard or file spec";
                break;
            case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
                extraStr = "extra" + extra + " : MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK --> : The video is streamed and its container is not valid for progressive playback i.e the video's index (e.g moov atom) is not at the start of the file";
                break;
            case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                extraStr = "extra" + extra + " : MEDIA_ERROR_SERVER_DIED --> : Media server died. In this case, the application must release the MediaPlayer object and instantiate a new one";
                break;
            case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
                extraStr = "extra" + extra + " : MEDIA_ERROR_TIMED_OUT --> : Some operation takes too long to complete, usually more than 3-5 seconds";
                break;
            case MediaPlayer.MEDIA_ERROR_UNKNOWN:
                extraStr = "extra" + extra + " : MEDIA_ERROR_UNKNOWN --> : Unspecified media player error.";
                break;
            case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
                extraStr = "extra" + extra + " : MEDIA_ERROR_UNSUPPORTED --> : the media framework does not support the feature";
                break;
        }
        if (!TextUtils.isEmpty(whatStr)) {
            Tracker_Google.getInstance().addEvent("OnErrorListener", whatStr, extraStr);
        }
    }

    public static void errorTracker(int what, int extra) {
        try {
            switchTracker(0, what, extra);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

// switch (extra) {
//            case 800:
//                Log.d(TAG, "MEDIA_INFO_BAD_INTERLEAVING");
//                break;
//            case 702:
//                Log.d(TAG, "MEDIA_INFO_BUFFERING_END");
//                break;
//            case 701:
//                Log.d(TAG, "MEDIA_INFO_METADATA_UPDATE");
//                break;
//            case 802:
//                Log.d(TAG, "MEDIA_INFO_METADATA_UPDATE");
//                break;
//            case 801:
//                Log.d(TAG, "MEDIA_INFO_NOT_SEEKABLE");
//                break;
//            case 1:
//                Log.d(TAG, "MEDIA_INFO_UNKNOWN");
//                break;
//            case 3:
//                Log.d(TAG, "MEDIA_INFO_VIDEO_RENDERING_START");
//                break;
//            case 700:
//                Log.d(TAG, "MEDIA_INFO_VIDEO_TRACK_LAGGING");
//                break;
//        }
